/*表单参数获取方法*/

import globalMethods from "@/plugins/methods";
import {useBaseInfoWithOut} from "@/store/modules/base-info";


const useBaseInfo = useBaseInfoWithOut();
export default function (params) {
  const {cap4} = useBaseInfo.baseInfo?.zwIframe || {};
  //不编辑权限的不需要校验提示
  let isBrowse = cap4?.type === 'browse';
  const zwIframe = window._getZWIframe();
  return new Promise((resolve) => {
    //绑定一个函数,将表单转异步方式调用保存表单数据的结果
    zwIframe.csdk.core.getSubmitData(params);
    return params.callback(resolve);
  }).then((formData) => {
    return new Promise(resolve => {
      if (!formData) {
        return resolve();
      }
      const {
        regexAsync
      } = formData || {};
      if (params.checkNull){
        formData.content.checkNull = '1';
      }
      if (!isBrowse && regexAsync && regexAsync.isUnforce === '1' && !useBaseInfo.regexAsync) {
        globalMethods.confirm({
          //正则弱校验提示
          title: $.i18n('system.reminder.title'),
          content: (h) => {
            const data = {
              domProps: {
                innerHTML: regexAsync.unforceMsg
              }
            }
            return <div {...data}></div>
            },
            okText: $.i18n('common.content.goon'),
            onCancel: () => {
              resolve();
            },
            onOk: () => {
              useBaseInfo.regexAsync = true;
              resolve(formData);
            }
          });
        }else {
          resolve(formData);
        }
      })
  })
}